
using System;
using System.Collections;
using System.Web.UI.WebControls;

namespace GiftNet.Model
{
	#region District Model -(by fangyifeng at 2007-09-14 12:24:02)

	/// <summary>
	/// District object'District'.
	/// </summary>
	[Serializable]
	public class District : System.IComparable
		{
		#region Member Variables
		
		protected Guid _id;
		protected string _nme;
		protected string _nameE;
		protected City _city;
		
		protected static String _sortExpression = "Id";
		protected static SortDirection _sortDirection = SortDirection.Ascending;

		#endregion

		#region Constructors

		public District() { }

		public District( string nme, string nameE, City city )
		{
			this._nme = nme;
			this._nameE = nameE;
			this._city = city;
		}

		#endregion

		#region Public Properties

		public virtual Guid Id
		{
			get {return _id;}
			set {_id = value;}
		}

		public virtual string Nme
		{
			get { return _nme; }
			set
			{
				if ( value != null && value.Length > 40)
					throw new ArgumentOutOfRangeException("Invalid value for Nme", value, value.ToString());
				_nme = value;
			}
		}

		public virtual string NameE
		{
			get { return _nameE; }
			set
			{
				if ( value != null && value.Length > 80)
					throw new ArgumentOutOfRangeException("Invalid value for NameE", value, value.ToString());
				_nameE = value;
			}
		}

		public virtual City City
		{
			get { return _city; }
			set { _city = value; }
		}

		
        public static String SortExpression
        {
            get { return _sortExpression; }
            set { _sortExpression = value; }
        }

        public static SortDirection SortDirection
        {
            get { return _sortDirection; }
            set { _sortDirection = value; }
        }
		#endregion
		
        #region IComparable Methods
        public virtual int CompareTo(object obj)
        {
			if (!(obj is District))
				throw new InvalidCastException("This object is not of type District");
			
			int relativeValue;
			switch (SortExpression)
			{
				case "Id":
					relativeValue = this.Id.CompareTo(((District)obj).Id);
					break;
				case "Nme":
					relativeValue = this.Nme.CompareTo(((District)obj).Nme);
					break;
				case "NameE":
					relativeValue = (this.NameE != null) ? this.NameE.CompareTo(((District)obj).NameE) : -1;
					break;
                default:
                    goto case "Id";
			}
            if (District.SortDirection == SortDirection.Ascending)
				relativeValue *= -1;
			return relativeValue;
		}
		#endregion
	}

	#endregion
}
